:- module(pkg_list,[get_pkg/4,del_pkg/1]).

:- use_module(db(database_impl)).
:- use_module(db(database_access)).


get_pkg(K,Name,Desc,Author):-
	retrieve(K,resource(K,AssetKey,_,_,_,_)),
	retrieve(AssetKey,asset(AssetKey,_,_,Name,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)),
	get_first_author(AssetKey,Author),
	get_pkg_descriptions(AssetKey,Desc).

get_first_author(AssetKey,Name):-
	retrieve(authors(AssetKey,UserKey)),
	retrieve(UserKey,user(UserKey,OrgKey,_)),
	retrieve(OrgKey,organization(OrgKey,Name)),
	!.

get_pkg_descriptions(AssetKey,LD):-
	findall(
		   D,
		   retrieve(descriptions(AssetKey,D)),
		   LD
	       ).

del_pkg(K):-
	resource_delete(K).



	
